package com.cloud.eureka.client.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 2020/3/16
 * EurekaClientDemoController
 *
 * @author machuanpeng
 */
@RestController
@RequestMapping("/eureka/client")
public class EurekaClientDemoController {

    @Value("${server.port}")
    String port;

    @GetMapping("/home")
    public String home(@RequestParam(value = "name", defaultValue = "eureka") String name) {
        return "name:" + name + " ,port:" + port;
    }

    /**
     * 文件上传.
     * 2020/3/18
     *
     * @param file file
     * @return java.lang.String
     * @author machuanpeng
     */
    @PostMapping(value = "/uploadFile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public String uploadFile(@RequestPart(value = "FeignFile") MultipartFile file) {
        return "port:" + port + ",fileName:" + file.getName();
    }
}
